package config

import (
	"fmt"
	"github.com/spf13/viper"
	"log"
)

var instance *config

type config struct {
	*viper.Viper
}

func init() {
	instance = &config{viper.New()}

	instance.SetConfigType("yaml")
	instance.SetConfigFile("./config.yaml")

	if err := instance.ReadInConfig(); err != nil {
		log.Fatalf("config file read err %s", err.Error())
	}

	keys := instance.AllKeys()
	for _, key := range keys {
		fmt.Println(key, ":", instance.Get(key))
	}
}

func GetInstance() *config {
	return instance
}
